package com.rams.ls.gui.form;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;

import com.rams.ls.Config;

import net.miginfocom.layout.CC;
import net.miginfocom.layout.LC;
import net.miginfocom.swing.MigLayout;

public class FormMobs extends BasicForm{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3940387207549738905L;

	private static final JToolBar tbSearchOptions = new JToolBar();
	private static final JToolBar tbLvlOptions = new JToolBar();
	private static final JToolBar tbResistsOptions = new JToolBar();
	private static final JPanel tbSubPanel = new JPanel();
	private static final JPanel dataPanel = new JPanel();
	private static final JPanel mobInfoPanel = new JPanel(); 
	
	public FormMobs() {
		this.setLayout(new MigLayout(new LC().debug(Config.debug).fill()));
		
		initSearchOptionsToolbar();
		tbSearchOptions.setFloatable(false);
		this.add(tbSearchOptions, new CC().dockNorth());
		
		initLvlOptionsToolbar();
		
		tbSubPanel.add(tbLvlOptions);
		this.add(tbSubPanel, new CC().dockWest());
		
		dataPanel.setLayout(new MigLayout(new LC().debug(Config.debug).fill()));
		initDataPanel();
		this.add(dataPanel, new CC().dockNorth().growY());
	}
	
	private void initDataPanel() {
		final DefaultListModel mobsListModel = new DefaultListModel();
		final JList mobsList = new JList(mobsListModel);
		final JScrollPane mobsListScroll = new JScrollPane(mobsList);
		
		dataPanel.add(mobsListScroll, new CC().growY());
		
		mobInfoPanel.setLayout(new MigLayout(new LC().debug(Config.debug).fill()));
		
		initMobInfoPanel();
		dataPanel.add(mobInfoPanel);
		
	}
	
	private void initMobInfoPanel() {
		final DefaultListModel dropListModel = new DefaultListModel();
		final JList dropList = new JList(dropListModel);
		final DefaultListModel spoilListModel = new DefaultListModel();
		final JList spoilList = new JList(spoilListModel);
		final JScrollPane dropListScroll = new JScrollPane(dropList);
		final JScrollPane spoilListScroll = new JScrollPane(spoilList);
		final JPanel mobInfo = new JPanel();
		
		mobInfoPanel.add(mobInfo, new CC().dockNorth());
		mobInfoPanel.add(dropListScroll, new CC().dockNorth());
		mobInfoPanel.add(spoilListScroll, new CC().dockNorth());
	}
	
	private void initSearchOptionsToolbar() {
		JButton lvl = new JButton("Lvl");
		lvl.setActionCommand("lvl");
		lvl.addActionListener(new SearchOptionsActionListener());
		tbSearchOptions.add(lvl);
		
		JButton resist = new JButton("Resist");
		resist.setActionCommand("resist");
		resist.addActionListener(new SearchOptionsActionListener());
		tbSearchOptions.add(resist);
		
		JButton npc = new JButton("NPC");
		npc.setActionCommand("npc");
		npc.addActionListener(new SearchOptionsActionListener());
		tbSearchOptions.add(npc);
		
		JButton raid = new JButton("Raid");
		raid.setActionCommand("raid");
		raid.addActionListener(new SearchOptionsActionListener());
		tbSearchOptions.add(raid);
		
		JButton quest = new JButton("Quest");
		quest.setActionCommand("quest");
		quest.addActionListener(new SearchOptionsActionListener());
		tbSearchOptions.add(quest);
	}
	
	private class SearchOptionsActionListener implements ActionListener {

		public void actionPerformed(ActionEvent arg0) {
			
		}
		
	}

	private void initLvlOptionsToolbar() {
		int lvl = 0;
		
		for (int i = 1; i < 9; i++) {
			JButton lvlBtn = new JButton((lvl) + "-" + (lvl + 10));
			lvl = lvl + 10;
			tbLvlOptions.add(lvlBtn);
		}
		
		tbLvlOptions.setFloatable(false);
		tbLvlOptions.setOrientation(JToolBar.VERTICAL);
	}
}
